local assets =
{
    -- Asset("ANIM", "anim/panda_fisherman_supply_pack.zip"),
    -- Asset( "IMAGE", "images/inventoryimages/panda_fisherman_supply_pack.tex" ),  -- 背包贴图
    -- Asset( "ATLAS", "images/inventoryimages/panda_fisherman_supply_pack.xml" ),
}

local function create_common(bankandbuild)
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddSoundEmitter()
    inst.entity:AddNetwork()

    inst:AddTag("structure")
    inst:AddTag("stickheads")
    inst:AddTag("beaverchewable")  -- for werebeaver
    inst:AddTag("fridge")

    inst.AnimState:SetBank(bankandbuild)
    inst.AnimState:SetBuild(bankandbuild)
    inst.AnimState:PlayAnimation("idle_asleep")

    inst.entity:SetPristine()



    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("npc_base_lib")

    -- inst:AddComponent("inspectable") --可检查组件
    
    -- inst:AddComponent("inventoryitem")
    -- inst.components.inventoryitem:ChangeImageName("wereitem_beaver")
        -- inst.components.inventoryitem.imagename = "panda_fisherman_supply_pack"
    -- inst.components.inventoryitem.atlasname = "images/inventoryimages/panda_fisherman_supply_pack.xml"
	-- inst.components.inventoryitem.cangoincontainer = true


    inst:AddComponent("named")
    -- inst.components.named:SetName(tostring(_table.Name))

    inst:ListenForEvent("Set",function(inst,_table)
        -- _table = {
        --     pt = Vector3(0,0,0),
        --     color = Vector3(255,255,255),
        --     a = 0.1,
        --     awake = true,
        --     fire = true,
        -- }
        if _table == nil then
            return
        end
        if _table.pt and _table.pt.x then
            inst.Transform:SetPosition(_table.pt.x,_table.pt.y,_table.pt.z)
        end

        if _table.color and _table.color.x then
            if _table.MultColour_Flag ~= true then
                inst:AddComponent("colouradder")
                inst.components.colouradder:OnSetColour(_table.color.x/255 , _table.color.y/255 , _table.color.z/255 , _table.a or 1)
            else
                inst.AnimState:SetMultColour(_table.color.x,_table.color.y, _table.color.z, _table.a or 1)
            end
        end

        if _table.awake == true  then
            if inst.awake ~= true then
                inst.awake = true
                inst.AnimState:PlayAnimation("wake")
                inst.AnimState:PushAnimation("idle_awake", false)
                if _table.fire == true then
                    inst._fire_fx =inst:SpawnChild("npc_fx_fire")
                    inst._fire_fx:PushEvent("Set",{pt = Vector3(0,0,0)})
                end
            end
        else
            inst.awake = false
            inst.AnimState:PlayAnimation("sleep")
            inst.AnimState:PushAnimation("idle_asleep", false)
            if inst._fire_fx then
                inst._fire_fx:Remove()
                inst._fire_fx = nil
            end
        end
        inst.Ready = true
    end)

    inst:DoTaskInTime(0,function()
        if inst.Ready ~= true then
            inst:Remove()            
        end
    end)

    return inst
end


local function pig_head()
    local inst = create_common("pig_head")
    if not TheWorld.ismastersim then
        return inst
    end
    return inst
end
local function create_mermhead()
    local inst = create_common("merm_head")

    if not TheWorld.ismastersim then
        return inst
    end

    --inst.components.lootdropper:SetLoot({"spoiled_food", "spoiled_food", "twigs", "twigs"})

    return inst
end


return Prefab("npc_item_pig_head_stick", pig_head,assets)